package com.websocket.demo.config;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

@Controller
@RequestMapping("/send")
public class CheckCenterController {

    /**
     * 进入首页面
     * @param
     * @return
     */
    @GetMapping("/home/{userid}")
    public ModelAndView home(@PathVariable String userid) {
        ModelAndView mav = new ModelAndView("/index2");
        mav.addObject("userid", userid);
        return mav;
    }

    //推送数据接口
    @ResponseBody
    @RequestMapping("/socket/push/{userid}")
    public Object pushToWeb(@PathVariable String userid, String title,String message) {
        try {
            WebSocketServer.sendInfo(title,message, userid);
        } catch (IOException e) {
            e.printStackTrace();
            return userid + "#" + e.getMessage();
        }
        return userid;
    }
}
